<?php
class upload extends spController
{
	function uploadTMPFile(){
		$response_data = array();
		if (!empty($_FILES)) {
			if (  $_FILES['Filedata']['error'] == 0 ) {
			$tempFile = $_FILES['Filedata']['tmp_name'];
			$file_type = Util::getFileExt($_FILES['Filedata']['name']);
			$targetPath = UPLOAD_TMP_DIR.'/';
			
			$fileName = time().'.'.Util::makeRandomStr(5).'.'.$file_type;
			$targetFile =  $targetPath.$fileName;
			$return_value = move_uploaded_file($tempFile,$targetFile);
			
			if ( $return_value ) {
			$response_data['data'] = array();
			$response_data['data']['tmpname'] = $fileName;
			$response_data['error'] = '';
			} else {
				$response_data['error'] = 'can not move '.$tempFile;
			}
			} else if( $_FILES['Filedata']['error'] == 1 ){
				$response_data['error'] = 'Uloaded file max size '.ini_get('upload_max_filesize');
			} else {
				$response_data['error'] = 'upload error';
			}
		}else{
			$response_data['error'] = 'No file selected';
		}
		echo json_encode($response_data);
		exit();
	}
}